
<title>Item Control Page</title>

<?php  

/*

***************************************
*                                     *
* Copyright 2011 David Matthew Pugh   *
* Contact Info:thebravedave@gmail.com *
*                                     *
***************************************

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
  
require_once "../services/webservices.php";
require_once "index.php";
require_once("../Pagination.php");
  
   
?>



<br />
<br />


<div class="leftfloatbar">
<b><a href="getitem.php?v=all&limit=10&page=1" >Get All Items</a></b>
<br />
</form>

<br />
<form action="getitem.php?v=category" method="GET" id="getitembyCategoryForm" name="getitembyCategoryForm">
<input type="hidden" name="v" value="category"/>
<input type="hidden" name="limit" value="10"/>
<input type="hidden" name="page" value="1" />
<select name="Category_ID">
<option value="0">Select a Category...</option>
<?php

if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['Delete_Button']))
{
    $gw_id = $_GET['gw_id'];
    $item = new item();
    $item->gw_id = $gw_id;
    $item->deleteitemandrelateddata();
    
}

$getRequest = new itemcategory();
$getResponse = $getRequest->getallitemcategories();

//Loop through returned XML and display all items        
$xml = new SimpleXMLElement($getResponse);

$Item_Count = $xml->Item_Count;

if($Item_Count > 0)
{
       
    foreach ($xml->Item as $eachItem)         
    {
        $category_id = $eachItem->category_id;
        $category = $eachItem->category;            
?>
        <option value="<?php echo $category_id;?>" onclick="document.getitembyCategoryForm.submit();"><?php echo $category;?></option>
<?php
    }
}
else
{
?>
        <option value="0">No Categories Found.</option>
<?php
}        
?>
</select>
</form>
<form action="getitem.php?v=title" method="GET" id="getitembynameform" name="getitembynameform">
<input type="hidden" id="v" name="v" value="title">
<input type="hidden" name="limit" value="10"/>
<input type="hidden" name="page" value="1" />
<input type="text" id="title" name="title" size="35" value="get item by item name" onclick="this.focus();this.select();">
</form>
</div>

<br />
<br />
<br />
<br />



<br /><br />
<?php
 
$xmltrigger = "false";
if(isset($_GET['v']))
{   
    
    $limit = $_GET['limit'];
    $page = $_GET['page'];
    if($_GET['v'] == "all")
    {    
        $getRequest = new item();  
        $getRequest->page = $page;
        $getRequest->limit = $limit;                  
        $getResponse = $getRequest->getallitems();
        $xmltrigger = "true";
    }
        
    if($_GET['v']== "category")
    {    
        $getRequest = new item(); 
        $getRequest->page = $page;
        $getRequest->limit = $limit;          
        if(isset($_GET['Category_ID']))
        {         
            $getRequest->category_id = $_GET['Category_ID'];
            $getResponse = $getRequest->getgeneralitembycategory();
            $xmltrigger = "true";  
        }
        
    }
    if($_GET['v'] == "title")
    {   
        $getRequest = new item();  
        $getRequest->page = $page;
        $getRequest->limit = $limit;    
        if(isset($_GET['title']))
        {           
            $getRequest->item_name = $_GET['title'];
            $getResponse = $getRequest->getitembyname();
            $xmltrigger = "true";  
        }
        
        
    }
 
    if($xmltrigger == "true")
    {
      
        
        //Loop through returned XML and display all items        
        $xml = new SimpleXMLElement($getResponse);
        $Item_Count = $xml->Item_Count;
        if($Item_Count > 0)
        {
            
            $Pagination = new Pagination();
            
            if(isset($_GET['Category_ID']))
            {
                $category_id = $_GET['Category_ID']; 
                $Pagination->addToUrlVarArray("Category_ID=$category_id");  
            }
            if(isset($_GET['v']))
            {
                $v = $_GET['v'];
                $getbyvString = "v=$v";            
            } 
            $targetPage = "getitem.php"; 
            $limitString = "limit=$limit";
            
            $Pagination->setLimit($limit);
            $Pagination->setPage($page);
            $Pagination->setTargetPage($targetPage);
            $Pagination->setTotalItems($Item_Count);
            
            $Pagination->addToUrlVarArray($getbyvString);
            $Pagination->addToUrlVarArray($limitString);
            
            
            $Pagination->setUrlVariables();

            
            
            foreach ($xml->Item as $eachItem)         
            {
                $gw_id = $eachItem->gw_id;
                $gw_id = (int)$gw_id;
                if(isset($eachItem->specialized))
                {
                    $specialized = $eachItem->specialized;
                    $specialized = (string)$specialized; 
                }
                else
                {
                    $specialized = "null";   
                } 
                
                $getrequest1 = new itemspecialization();
                $getrequest1->gw_id = $gw_id;
                $getresponse1 = $getrequest1->getspecificwidgetbygwid();
                $xml = new SimpleXMLElement($getresponse1);
                $numinswid = $xml->Item_Count;
                $numinswid = (int)$numinswid;
                if($numinswid == 0)
                {
                    $specialized = "false";
                }
                else
                {
                    $specialized = "true";
                }
                $gw_id = $eachItem->gw_id;
                $gw_name = $eachItem->gw_name;            
                $category = $eachItem->category;          
                $image = urldecode($eachItem->image);
                $price = $eachItem->price; 
                $in_stock = $eachItem->in_stock;  
?>

                <div class="margin25percent"> 
                <div class="smallcorerightmargin"> 
                <img src="<?php echo $image ?>" width="100" height="100"></img><br />   
                <b>Item Name:</b> <?php echo $gw_name; ?><br />
                <b>Item ID:</b> <?php echo $gw_id; ?><br />
                <b>Category Name:</b> <?php echo $category;?><br />  
               
<?php
                if($specialized == "true")
                {
                    echo '<b>Specialized:</b>' . $specialized . '<br />';
                }
                else
                {
                    echo '<b>Specialized:</b>' . $specialized . '<br />';
                    echo '<b>Price:</b>' . $price . '<br />';       
                    echo '<b>Qty:</b>' . $in_stock . '<br />';
                }       
                ?>
                
                <div style="display:block;margin:10px;">
                <form action="updateitem.php" method="POST" style="display: inline;">
                <input type="hidden" id="gw_id" name="gw_id" value="<?php echo $gw_id;?>">
                <input type="hidden" id="category_id" name="category_id" value="<?php echo $category_id;?>">  
                <input type="submit" id="Edit_Button" name="Edit_Button" value="Edit">
                </form>

                <form action="getitem.php" method="GET" style="display: inline;">
                <input type="hidden" id="gw_id" name="gw_id" value="<?php echo $gw_id;?>">
                <input type="hidden" id="category_id" name="category_id" value="<?php echo $category_id;?>">
                <input type="submit" id="Delete_Button" name="Delete_Button" value="Delete" onclick="javascript: return confirm('Deleting this item will delete all item, item specialization and all inventory control information.  Are you sure you want to delete this item: <?php echo $gw_name?>?');">
                <br />
                </form>
                </div> 
                </div>
<?php
                
                echo '</div>'; 
                }
                echo $Pagination->getEmbeddedCssStyling();
                $Pagination->getPaginationLinkBar(); 
        }
        else
        {
           
            ?>
            No items found.<br />
            <?php
        } 
     }              
}
else
{
?>

<?php
}  
?>
 <br />
 <br />
 <br />
 <br /> 
 <br />
 </div>
 </body>
 </html>   
   

